package com.hundsun.yr.universal.p2p.ui.view;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.hundsun.mobile.zwgt.R;






/**
 * @Title: ProgressDailog.java 
 * @Description: 加载进度框
 * @date 2016-1-7 下午5:13:29 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class ProgressDailog extends Dialog {

	private TextView msg=null;

	public ProgressDailog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public ProgressDailog(Context context, int theme) {
		super(context, theme);
		initProgress(context);
	}

	/**
	 * progress 加载
	 * 
	 * @param context
	 */
	@SuppressLint("InflateParams")
	public void initProgress(Context context) {

		// 加载布局文件
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.view_dialog_progress, null);
		msg = (TextView) view.findViewById(R.id.tv_loadingmsg);
		getWindow().setBackgroundDrawableResource(android.R.color.transparent);
		setCancelable(false);
		setCanceledOnTouchOutside(false);
		// dialog添加视图
		setContentView(view);

	}

	/**
	 * 显示加载框
	 * @param tipText
	 */
	public void showProgress(String tipText) {
		
		try {
			setCancelable(false);
			setCanceledOnTouchOutside(false);
			msg.setText(tipText);
			show();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	/**
	 * 显示加载框
	 * @param tipText
	 * @param canclable 是否可以返回取消 
	 * @param touchoutside 是否可以点击其他区域取消
	 */
	public void showProgress(Object content, boolean canclable,boolean touchoutside) {

		setCancelable(canclable);
		setCanceledOnTouchOutside(touchoutside);
		if(content instanceof Integer){
			msg.setText((Integer)content);
		}else if(content instanceof String){
			msg.setText((String)content);
		}
		show();
	}

	/**
	 * 显示加载框
	 * @param tipres
	 */
	public void showProgress(Object content) {
		try {
			setCancelable(false);
			setCanceledOnTouchOutside(false);
			if(content instanceof Integer){
				msg.setText((Integer)content);
			}else if(content instanceof String){
				msg.setText((String)content);
			}
			show();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	
	/**
	 * 显示加载框
	 */
	public void showProgress() {
		try {
			setCancelable(false);
			if(msg!=null){
				msg.setText(R.string.loading);
			}
			show();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	
	/**
	 * 取消加载框
	 */
	public void closeProgress() {
		try {
			dismiss();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	public void setText(String text) {
		if(msg!=null){
			msg.setText(text);
		}
	}
}
